using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Menu_testmenu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsCallback)
            BindMenu();
    }

    private void BindMenu()
    {
        // .Providers["SecuritySiteMap"].RootNode
        foreach (SiteMapNode adminNode in SiteMap.RootNode.ChildNodes)
        {
            AddItem(adminNode.Title, adminNode.Url); 
            AddChilds(adminNode);
            /*
            HtmlAnchor a = new HtmlAnchor();
            
            a.HRef = adminNode.Url;
            a.InnerHtml = "<span>" + Translate(adminNode.Title) + "</span>";
            if (Request.RawUrl.EndsWith(adminNode.Url, StringComparison.OrdinalIgnoreCase))
                a.Attributes["class"] = "current";
            HtmlGenericControl li = new HtmlGenericControl("li");
            li.Controls.Add(a);
            
            ulMenu.Controls.Add(li);
            */
        }

       // if (!Request.RawUrl.ToUpperInvariant().Contains("/ADMIN/"))
       //     AddItem(Resources.labels.changePassword, Utils.RelativeWebRoot + "login.aspx");
    }

    private void AddChilds(SiteMapNode adminNode)
    {
        foreach (SiteMapNode n in adminNode.ChildNodes)
        {
            if (n.ChildNodes.Count > 0) {
                
                AddChilds(n); } else { AddItem(n.Title, n.Url); }
        }
    }

    public void AddItem(string text, string url)
    {
        HtmlAnchor a = new HtmlAnchor();
        a.InnerHtml = "<span>" + text + "</span>";
        a.HRef = url;

        HtmlGenericControl li = new HtmlGenericControl("li");
        li.Controls.Add(a);
        ulMenu.Controls.Add(li);
    }

    public string Translate(string text)
    {
        try
        {
            return this.GetGlobalResourceObject("labels", text).ToString();
        }
        catch (NullReferenceException)
        {
            return text;
        }
    }
}
